/*
 * @Author: boyyang
 * @Date: 2022-02-13 11:37:21
 * @LastEditTime: 2022-02-13 12:07:50
 * @LastEditors: boyyang
 * @Description: 
 * @FilePath: \boyyang\src\directive\lazyLoad.ts
 */

export default {
    mounted(el: HTMLElement, binding: any) {
        const io = new IntersectionObserver((entries) => {
            console.log(entries)
            entries.forEach(entry => {
                let lazyImage = entry.target as HTMLImageElement
                if (entry.intersectionRatio > 0) {
                    lazyImage.src = binding.value
                    io.unobserve(lazyImage)
                }
            })
        })

        io.unobserve(el)
    }
}





